package com.yth.bean;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.stereotype.Component;

/**
 * 对于实例化过程复杂的bean，可以考虑FactoryBean
 *
 * @author yutianhong
 * @version 1.0
 * @since 2023/09/05 15:40
 */
@Slf4j
@Component
public class TestFactoryBean implements FactoryBean<TestFactoryBean.ComplexBean> {

    @Override
    public ComplexBean getObject() throws Exception {
        log.info("[FactoryBean::getObject]");
        // 复杂的实例化逻辑 可以编写于此
        return new ComplexBean();
    }

    @Override
    public Class<?> getObjectType() {
        log.info("[FactoryBean::getObjectType]");
        return ComplexBean.class;
    }

    @Override
    public boolean isSingleton() {
        log.info("[FactoryBean::isSingleton]");
        return true;    // 默认是返回true
    }

    public static class ComplexBean {
    }
}
